//
//  Model_message.m
//  KWNLaywerClient
//
//  Created by 孔六五 on 15/1/16.
//  Copyright (c) 2015年 张明磊. All rights reserved.
//

#import "Model_message.h"

@implementation Model_message

- (void)getModel_messageWithDic:(NSDictionary *)dic
{
    NSString *content_ = [dic objectForKey:@"content"];

    NSArray *arr_img_ = [dic objectForKey:@"content_img"];
    NSString *head_src_ = [dic objectForKey:@"head_src"];
    NSString *id_ = [dic objectForKey:@"id"];
    
    NSArray *img_thumbnail_ = [dic objectForKey:@"img_thumbnail"];
    NSString *realname_ = [dic objectForKey:@"realname"];
    NSString *time_ = [dic objectForKey:@"time"];
    NSString *type_ = [dic objectForKey:@"type"];

    if(content_ && ![content_ isKindOfClass:[NSNull class]]){
        self.string_content = content_;
    }
    if(arr_img_ && ![arr_img_ isKindOfClass:[NSNull class]]){
        self.arr_img = arr_img_;
    }
    if(head_src_ && ![head_src_ isKindOfClass:[NSNull class]]){
        self.string_headUrl = head_src_;
    }
    if(id_ && ![id_ isKindOfClass:[NSNull class]]){
        self.string_id = id_;
    }
    if(img_thumbnail_ && ![img_thumbnail_ isKindOfClass:[NSNull class]]){
        self.arr_thumbnail = img_thumbnail_;
    }
    if(realname_ && ![realname_ isKindOfClass:[NSNull class]]){
        self.string_name = realname_;
    }
    if(time_ && ![time_ isKindOfClass:[NSNull class]]){
        self.string_time = time_;
    }
    if(type_ && ![type_ isKindOfClass:[NSNull class]]){
        self.string_type = type_;
    }
    
    //height (待处理)
    
    CGFloat height = 0;
    height = 10 + 20 + 10;    //10时间label与cell上边界距离 20(显示时间高度) 第二个10 时间lebel与之下控件的间隔
    
    if(self.string_content && self.string_content.length > 0)
    {
        CGSize messageSize = [UIUtils cgrectFor:self.string_content withFont:FontOfQuestionList labWidth:WidthMaxOfMessageImage - 25];      //-25前端气泡间隔15 后端气泡间隔10
        self.qMWidth_label = messageSize.width;
        if (messageSize.height + 10*2 > WidthOfHead + 30) {    //30名字label高度
            height = height + messageSize.height + 10*2 + 10;       //10*2label与气泡的间隔 10与之下控件的间隔或者cell的间隔
        }
        else
        {
            height = height + WidthOfHead + 30 + 10;               //10与之下控件的间隔或者cell的间隔
        }
    }
    
    if(self.arr_thumbnail && self.arr_thumbnail.count>0)
    {
        if (50 + 10*2 <= WidthOfHead + 30){                  //30名字label高度
            height = height + WidthOfHead + 30 + 5;

        }
        //目前执行不到
//        else{
//            height = 5*2 +50 + 10;                         //image高度50 10*2气泡间隔 10cell的间隔
//        }
    }
    
    self.qMHeight = height;
    
}

@end
